package logic

import (
	"C/models/mysql"
	"context"
	"fmt"

	"C/internal/svc"
	"C/shenzhousrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *shenzhousrv.GoodsInfoRequest) (*shenzhousrv.GoodsInfoResponse, error) {
	// todo: add your logic here and delete this line

	var goods mysql.Goods
	err := goods.FindGoods(int(in.GoodsId))
	if err != nil {
		return nil, fmt.Errorf("商品不存在")
	}
	return &shenzhousrv.GoodsInfoResponse{
		GoodsId: int64(goods.ID),
		Title:   goods.Title,
		Cover:   goods.Cover,
		Price:   float32(goods.Price),
		Likes:   int64(goods.Likes),
		Stock:   int64(goods.Stock),
		Status:  goods.Status,
	}, nil
}
